package com.abiao.shop.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Description: SnapMQConfig   秒杀消息队列配置类
 * @Author: AB
 * @Date: 2021-07-21
 * @Version:v1.0
 */
@Configuration
public class SnapMQConfig {
    public final static String SNAP_QUEUE = "snapQueue";
    public final static String SNAP_TOPIC_EXCHANGE = "snapTopicExchange";
    public final static String SNAP_Key = "snapKey";

    @Bean   //生成队列
    public Queue snapQueue(){
        return new Queue(SNAP_QUEUE,true);
    }

    /**
     * Exchange：topic模式,根据key指定队列发送，key可使用通配符（*表示一个字符，#表示0到多个字符）
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(SNAP_TOPIC_EXCHANGE);
    }
    @Bean   //绑定秒杀队列和交换机
    public Binding snapBind(){
        return BindingBuilder.bind(snapQueue()).to(topicExchange()).with(SNAP_Key);
    }
}
